<?php
include_once '../mysql/dbtools.php';
$conn = new mysqli();
$conn->connect('127.0.0.1','root','root','bank');
if(!empty($conn->connect_error)){
    echo 'MYSQL数据库连接错误: '.$conn->connect_error;
    die;
}

//echo '数据库连接成功!<br/>';

//银行卡号
DbTools::setConn($conn);
$data = DbTools::select('SELECT CardNo,CardPwd,RealName FROM bankcard JOIN accountinfo; ');
//print_r($data);
session_start();



$username =$_POST['username'];
$password =$_POST['password'];

$regUrl='';
$alter ='';
$userkey =md5($username.$password);
$count=0;

foreach ($data as $datum) {

    if (!($datum['CardNo']==$username&&$datum['CardPwd']==$password)){
        $alter='用户名或密码错误';
        $regUrl='../login.php';
    }else{
        $realname =$datum['RealName'];
        setcookie('userkey',$userkey,time()+24*3600,'/');
        $alter='登陆成功';
        $regUrl='userinfo.php';

        $_SESSION[$userkey]=[
            'username'=>$username,
            'password'=>$password,
            'realname'=>$realname
        ];
        break;
    }
}
?>

<html>
<body>
    <input type="hidden" id="alter" value="<?php echo $alter?>">
    <input type="hidden" id="regUrl" value="<?php echo $regUrl?>">

</body>
<script>
  onload=function () {
      var alter =document.getElementById('alter').value;
      var regUrl =document.getElementById('regUrl').value;
      alert(alter);
      location.href=regUrl;
  }

</script>
</html>
